package youleche.com.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * 文件工具类
 * @author Administrator
 *
 */
public class FileUtil {
	/** 
    * 复制单个文件 
    * @param oldPath String 原文件路径 如：c:/fqf.txt 
    * @param newPath String 复制后路径 如：f:/fqf.txt 
    * @return boolean 
    */ 
  public static void copyFile(String oldPath, String newPath) { 
      try { 
          int bytesum = 0; 
          int byteread = 0; 
          File oldfile = new File(oldPath); 
          if (oldfile.exists()) {                  //文件存在时 
              InputStream inStream = new FileInputStream(oldPath);      //读入原文件 
              FileOutputStream fs = new FileOutputStream(newPath); 
              byte[] buffer = new byte[1444]; 
              int length; 
              while ( (byteread = inStream.read(buffer)) != -1) { 
                  bytesum += byteread;            //字节数 文件大小 
                  fs.write(buffer, 0, byteread); 
              } 
              
              inStream.close(); 
          } 
      }  catch (Exception e) { 
          e.printStackTrace(); 
      } 
  } 
  
  /**
   * 删除文件
   * @param imgName 图片名字
   * @param fileDic 文件目录
   */
  public static void deleteFile(String imgName, String fileDic){
	  File file = new File(fileDic +imgName);
	  if(file.exists()){
	  	  file.delete();
	  }
  }
  
}
